package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"strings"
)

func LimitReader(r io.Reader, n int) io.Reader {
	reader := bufio.NewReader(r)
	var by []byte
	a, err := reader.Read(by)
	fmt.Println(string(by))
	if err != nil {
		print(err)
	}
	if a > n {
		return bytes.NewReader(by[:n])
	} else {
		return bytes.NewReader(by)
	}
}

func main() {
	reader := LimitReader(strings.NewReader("hello world!"), 6)
	var data []byte
	reader.Read(data)
	fmt.Println(string(data))
}
